package com.aoxin.controller.course.systemCourse;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.aoxin.model.course.AloneCoursePage;
import com.aoxin.service.inter.course.systemCourse.AloneCoursePageService;
import com.aoxin.util.AjaxRes;
import com.aoxin.util.Const;
@RestController
@RequestMapping("/web/system/")
public class AloneCoursePageController {
    @Autowired
    private AloneCoursePageService aloneCoursePageService;
    /**
     * 查询课程包（系统管理员）
     * @param aloneCoursePage
     * @return
     */
    @RequestMapping("getAloneCoursePage")
    public AjaxRes getAloneCoursePage(AloneCoursePage aloneCoursePage,Integer state, AjaxRes res) {
        try {
            List<AloneCoursePage> page = aloneCoursePageService.getAloneCoursePage(aloneCoursePage,state);
            res.setSucceed(page);
        } catch (Exception e) {
            res.setFailMsg(e.getMessage());
            e.printStackTrace();
        }
        return res;
    }
    /**
     * 新增课程包(系统管理员)
     * @param aloneCoursePage
     * @return
     */
    @RequestMapping("insertAloneCoursePage")
    public AjaxRes insertAloneCoursePage(AloneCoursePage aloneCoursePage, AjaxRes res) {
        try {
   //     	aloneCoursePage.setDescription(aloneCoursePage.getDescription().replaceAll("$aoxin", "#"));
            aloneCoursePageService.insertAloneCoursePage(aloneCoursePage);
            res.setSucceed(aloneCoursePage.getCoursePageId());
        } catch (Exception e) {
            res.setFailMsg(e.getMessage());
            e.printStackTrace();
        }
        return res;
    }
    /**
     * 修改课程包
     * @param aloneCoursePage
     * @return
     */
    @RequestMapping("updateAloneCoursePage")
    public AjaxRes updateAloneCoursePage(AloneCoursePage aloneCoursePage, AjaxRes res) {
        try {
        	aloneCoursePage.setDescription(aloneCoursePage.getDescription().replaceAll("$aoxin", "#"));
            Integer col = aloneCoursePageService.updateAloneCoursePage(aloneCoursePage);
            res.setSucceed(col);
        } catch (Exception e) {
            e.printStackTrace();
            res.setFailMsg(e.getMessage());
        }
        return  res;
    }
    
    @RequestMapping("updateAloneCoursePageState")
    public AjaxRes updateAloneCoursePageState(@RequestParam("coursePageIds") List<Integer> coursePageIds,Integer state, AjaxRes res) {
        try {
            aloneCoursePageService.updateAloneCoursePageState(coursePageIds,state);
            res.setSucceed(Const.SUCCESS);
        } catch (Exception e) {
            e.printStackTrace();
            res.setFailMsg(e.getMessage());
        }
        return  res;
    }
    /**
     * 删除课程包
     * @param coursePageId
     * @return
     */
    @RequestMapping("deletePage")
    public AjaxRes deletePage(Integer coursePageId, AjaxRes res) {
        try {
            Integer col = aloneCoursePageService.deletePage(coursePageId);
            res.setSucceed(col);
        } catch (Exception e) {
            e.printStackTrace();
            res.setFailMsg(e.getMessage());
        }
        return  res;
    }
    /**
     * 查询主题课程（系统管理员）
     * @param aloneCoursePage
     * @return
     */
    @RequestMapping("getAloneCoursePageC")
    public AjaxRes getAloneCoursePageC(AloneCoursePage aloneCoursePage, AjaxRes res){
        try {
            List<AloneCoursePage> page = aloneCoursePageService.getAloneCoursePageC(aloneCoursePage);
            res.setSucceed(page);
        } catch (Exception e) {
            res.setFailMsg(e.getMessage());
            e.printStackTrace();
        }
        return res;
    }
    
    /**
     * 新增主题课程(系统管理员)
     * @param aloneCoursePage
     * @return
     */
    @RequestMapping("insertAloneCoursePageC")
    public AjaxRes insertAloneCoursePageC(AloneCoursePage aloneCoursePage, AjaxRes res) {
        try {
        	aloneCoursePage.setDescription(aloneCoursePage.getDescription().replaceAll("$aoxin", "#"));
            aloneCoursePageService.insertAloneCoursePageC(aloneCoursePage);
            res.setSucceed(aloneCoursePage.getCoursePageId());
        } catch (Exception e) {
            res.setFailMsg(e.getMessage());
            e.printStackTrace();
        }
        return res;
    }

    /**
     * 修改主题课程
     * @param aloneCoursePage
     * @return
     */
    @RequestMapping("updateAloneCoursePageC")
    public AjaxRes updateAloneCoursePageC(AloneCoursePage aloneCoursePage, AjaxRes res) {
        try {
        	aloneCoursePage.setDescription(aloneCoursePage.getDescription().replaceAll("$aoxin", "#"));
            Integer col = aloneCoursePageService.updateAloneCoursePage(aloneCoursePage);
            res.setSucceed(col);
        } catch (Exception e) {
            e.printStackTrace();
            res.setFailMsg(e.getMessage());
        }
        return  res;
    }
    
	/**
	 * 批量修改coursePageId
	 * @param coursePageIds
	 * @param ajaxRes
	 * @return
	 */
	@RequestMapping("/updateAloneCoursePageCState")
	public AjaxRes updateAloneCoursePageCState(@RequestParam("coursePageIds") List<Integer> coursePageIds, AjaxRes ajaxRes,Integer state) {
		try {
			this.aloneCoursePageService.updateAloneCoursePageCState(coursePageIds,state);
			ajaxRes.setSucceedMsg(Const.UPDATE_SUCCEED);
		} catch (Exception e) {
			ajaxRes.setFailMsg(e.getMessage());
		}
		return ajaxRes;
	}
    
    
    
    
}
